<%--

  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the latest version of the GNU Lesser General
  Public License as published by the Free Software Foundation;

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with this program (LICENSE.txt); if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

--%>
<%@ page errorPage="/WEB-INF/jsp/error.jsp"
    contentType="text/html; charset=utf-8"
%>
<%@ page pageEncoding="utf-8"%> 
<%@ include file="page-init.jsp" %>
<%@ include file="include.jsp" %>
<%@ page import="org.jamwiki.servlets.ServletUtil" %>
<%request.setCharacterEncoding("utf-8");%> 
<%
     String server = request.getServerName();
     int port = request.getServerPort();
     String hostport = "http://"+server+":"+port;
     int userid = 1;
     
 %>
<script type="text/javascript">
<!--

	 function creatNew(){
	     var fileName = document.all.item("topic").value;
	     var categoryId = document.all.item("categoryId").value;
	     var fileType = "topic";
	    // for(var i=0;i<document.searchForm.box.length;i++){           
        //     if(document.searchForm.box[i].checked)  
        //      fileType = document.searchForm.box[i].value;  
	    // }
	     fileType = document.searchForm.box.value; 
	     if(fileType == "topic"){
	        document.searchForm.submit();
	     }else{
		     openwindow("<%=hostport%>/jamwiki/ntko/edit.jsp?docType="+fileType+"&fileName="+encodeURI(fileName)+"&categoryId="+categoryId,'','','');
		     
		     
	     }
	 }
	 
	 String.prototype.trim = function()
     {
     // 用正则表达式将前后空格
     // 用空字符串替代。
     return this.replace(/(^\s*)|(\s*$)/g, "");
     }
	 
    function check(){
    if('<%=userid%>'<0){
           alert("对不起,你还没登录,不能起草！");
	      return false;
    }
     var fileName = document.all.item("topic").value;
	 var categoryId = document.all.item("categoryId").value;
     if(fileName.trim()==""){
	           alert("主题名不能为空！");
	           return false;
	     }else if(categoryId==""){
	          alert("你还没选择分类！");
	          return false;
	     }
      return true;
   }
   
    function check1(){ 
      return true;
   }
   function submitCreate(){
       document.searchForm.submit();
   }
   function selectCategory(){ 
      window.open("<%=request.getContextPath()%>/wiki/selectTree.jsp",'newwindow',"height=400, width=300, top=100, left=300, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
   }
        function GetName(ObjName)
    {   
        var str = ObjName;
        str = str.replace("$","_");
        var obj = document.getElementById(str);
        
	    showx = event.screenX - event.offsetX - 108 ; // + deltaX;
	    showy = event.screenY - event.offsetY + 18;   // + deltaY;
	    
    	var i;
    	i  = window.showModalDialog("<%=request.getContextPath()%>/wiki/selectTree.jsp",window, 
    	    "dialogWidth:300px; dialogHeight:400px;"+
    	    "dialogLeft:"+ showx + "px;" +
    	    "dialogTop:" + showy + "px;" +
    	    "status:no; directories:yes;scrollbars:no; Resizable=no; help=no"  
    	    );
        if (i != null)
        {
            obj.value = i;
        }
    }
   function editCategory(){  
   	  var categoryId = document.getElementById("categoryId").value; 
   	  var categoryName = document.getElementById("categoryName").value; 
   	  if(categoryName != null && '' != categoryName){
      	 openwindow("<%=request.getContextPath()%>/wiki/category.jsp?categoryId="+categoryId+"&categoryName="+encodeURI(categoryName),'460','156','');
      }else{
         alert('请先选择目录');
      }
   }
   function delCategory(){  
   	  var categoryId = document.getElementById("categoryId").value; 
   	  var categoryName = document.getElementById("categoryName").value; 
   	  if(categoryName != null && '' != categoryName){
      	 openwindow("<%=request.getContextPath()%>/wiki/delcategory.jsp?categoryId="+categoryId+"&categoryName="+encodeURI(categoryName),'460','156','');
      }else{
         alert('请选择目录');
      }
   }
   function concel(){
       document.getElementById("categoryId").value=""; 
   	   document.getElementById("categoryName").value=""; 
   	   document.getElementById("topic").value=""; 
   	   history.go(-1);
   }
//-->
</script>
<div align="center" >

<form name="searchForm" method="post" action="<jamwiki:link value="Special:Edit" />">
     <div align="center">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="36" align="left" valign="bottom" background="<%=imagePath %>right-bg.gif">&nbsp;</td>
        </tr>
        </table>
        <table width="460" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="9"><img src="<%=imagePath %>tanchu_01.jpg" width="9" height="28" /></td>
            <td align="center" background="<%=imagePath %>tanchu_02.jpg"><strong>起草</strong></td>
            <td width="10"><img src="<%=imagePath %>tanchu_03.jpg" width="10" height="28" /></td>
          </tr>
        </table>
        <table width="460" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="9" background="<%=imagePath %>tanchu_04.jpg">&nbsp;</td>
            <td bgcolor="eaeef7"><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td width="16%" height="30">主题类型：
                <label></label></td>
                <td width="84%" align="left">
                <select name="box" size="1">
                  <option value="topic">新建文本类型</option>
                  <option value="vsd">新建Visio类型</option>
                </select>
                </td>
              </tr>
              <tr>
                <td height="30">所属目录：</td>
                <td align="left"><label>
                 <input  size="40" type="hidden"  id="categoryId"  name="categoryId" value=""  >
                 <input  size="40" type="text" onclick="selectCategory();" name="categoryName" id="categoryName" value="" readonly>&nbsp;<!-- <span  style="cursor: hand"><input type="button" value="编辑" onclick="if(check1())editCategory();">&nbsp;&nbsp;<input type="button" value="删除" onclick="if(check1())delCategory();"></span> -->
                 <img alt="请选择所属分类" src="<%=imagePath %>/search.gif" border=0 name="to" id="to" onclick="selectCategory();"/>    
                </label></td>
              </tr>
              <tr>
                <td height="30">主题名称：</td>
                <td align="left"><input  size="40" type="text" name="topic" id="topic" value="" ></td>
              </tr>
              <tr>
                <td height="30" colspan="2" align="center"><input type="button"  value="确定" onclick="if(check())creatNew();" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button"  value="取消" onclick="concel()" />
                
                </td>
              </tr>
            </table></td>
            <td width="10"><img src="<%=imagePath %>tanchu_06.jpg" width="10" height="120" /></td>
          </tr>
        </table>
        <table width="460" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="9"><img src="<%=imagePath %>tanchu_07.jpg" width="9" height="9" /></td>
            <td width="" background="<%=imagePath %>tanchu_08.jpg"><img src="<%=imagePath %>tanchu_08.jpg" width="204" height="9" /></td>
            <td width="10"><img src="<%=imagePath %>tanchu_09.jpg" width="10" height="9" /></td>
          </tr>
        </table>
    </div>
</form>
</div>
<script type="text/javascript">document.searchForm.topic.focus();</script>
